package com.yyt.springbootjwt.service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.yyt.springbootjwt.domain.User;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author yeyangtao
 * @date 2020/5/22 14:24
 */
@Service
public class UserService {

    public String getToken(User user) {
        //过期时间
        long expireTime = System.currentTimeMillis() + 60 * 60 * 1000;
        return JWT.create()
                .withAudience(user.getId().toString())
                .withExpiresAt(new Date(expireTime))
                .sign(Algorithm.HMAC256(user.getPassword()));
    }

    public User findUserById(String userId) {
        return new User(10001L, "yyt", "123456");
    }
}
